import com.Lyy.entity.Course;
import com.Lyy.entity.Teacher;
import com.alibaba.druid.pool.DruidDataSource;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Text {
    @Test
    public void Text1() {
        ApplicationContext AContext = new ClassPathXmlApplicationContext("Bean.xml");
        Teacher teacher1 = AContext.getBean("Teacher", Teacher.class);
        System.out.println(teacher1);
        teacher1.tsc();
    }
    @Test
    public void Text2(){
        ApplicationContext Context = new ClassPathXmlApplicationContext("Bean.xml");
        Course course1 = Context.getBean("Course1", Course.class);
        course1.cc();
    }
    @Test
    public void Text3() throws SQLException {
        ApplicationContext Context = new ClassPathXmlApplicationContext("Bean.xml");
        DataSource dataSource = Context.getBean("dataSource", DruidDataSource.class);
        Connection connection = dataSource.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from students");
        while (resultSet.next()){
            System.out.println(resultSet.getInt("student_id")+" "+resultSet.getString("student_name")+"\n");
        }

        if (connection != null){
            connection.close();
        }
        if (statement != null){
            statement.close();
        }
        if (resultSet != null){
            resultSet.close();
        }
    }

}
